#include "FluxMapParameter.h"

#include <cmath>

#include <QDebug>

using namespace solar;

auto FluxMapParameter::getRevId() const -> int { return rev_id_; }
auto FluxMapParameter::getPixelNumX() const -> int { return pixel_num_.x(); }
auto FluxMapParameter::getPixelNumY() const -> int { return pixel_num_.y(); }
auto FluxMapParameter::getTotalPower() const -> float { return total_power_; }
auto FluxMapParameter::getMaximumFlux() const -> float { return maximum_flux_; }
auto FluxMapParameter::getMaximumFluxLocationX() const -> int { return maximum_flux_location_.x(); }
auto FluxMapParameter::getMaximumFluxLocationY() const -> int { return maximum_flux_location_.y(); }
auto FluxMapParameter::getFluxMapPath() const -> QString { return flux_map_path_; }
auto FluxMapParameter::getAlgorithmType() const -> int { return algorithm_type_; }

void FluxMapParameter::setRevId(int rev_id)
{
    if (rev_id_ != rev_id)
    {
        rev_id_ = rev_id;
        emit revIdChanged();
        qDebug() << "********** changed rev_id to: " << rev_id_;
    }
}

void FluxMapParameter::setPixelNumX(int pixel_num_x)
{
    if (pixel_num_.x() != pixel_num_x)
    {
        pixel_num_.setX(pixel_num_x);
        emit pixelNumXChanged();
        qDebug() << "********** changed pixel_num_x to: " << pixel_num_.x();
    }
}
void FluxMapParameter::setPixelNumY(int pixel_num_y)
{
    if (pixel_num_.y() != pixel_num_y)
    {
        pixel_num_.setY(pixel_num_y);
        emit pixelNumYChanged();
        qDebug() << "********** changed pixel_num_y to: " << pixel_num_.y();
    }
}

void FluxMapParameter::setTotalPower(float total_power)
{
    if (std::abs(total_power_ - total_power) < 1e-4)
    {
        total_power_ = total_power;
        emit totalPowerChanged();
        qDebug() << "********** changed total_power to: " << total_power_;
    }
}
void FluxMapParameter::setMaximumFlux(float maximum_flux)
{
    qDebug() << "   entering maximum flux change       ";
    if (std::abs(maximum_flux_ - maximum_flux) < 1e-4)
    {
        qDebug() << "    maximum flux change       ";
        maximum_flux_ = maximum_flux;
        emit maximumFluxChanged();
        qDebug() << "********** changed maximum_flux to: " << maximum_flux_;
    }
}
void FluxMapParameter::setMaximumFluxLocationX(int location_x)
{
    if (std::abs(maximum_flux_location_.x() - location_x) < 1e-4)
    {
        maximum_flux_location_.setX(location_x);
        emit maximumFluxLocationXChanged();
        qDebug() << "********** changed maximum_flux_location_x to: " << maximum_flux_location_.x();
    }
}
void FluxMapParameter::setMaximumFluxLocationY(int location_y)
{
    if (std::abs(maximum_flux_location_.y() - location_y) < 1e-4)
    {
        maximum_flux_location_.setY(location_y);
        emit maximumFluxLocationYChanged();
        qDebug() << "********** changed maximum_flux_location_y to: " << maximum_flux_location_.y();
    }
}
void FluxMapParameter::setFluxMapPath(QString flux_map_path)
{
    if (flux_map_path_ != flux_map_path)
    {
        flux_map_path_ = flux_map_path;
        emit fluxMapPathChanged();
        qDebug() << "********** changed flux_map_path to: " << flux_map_path_;
    }
}
void FluxMapParameter::setAlgorithmType(int algorithm_type)
{
    if (algorithm_type_ != algorithm_type)
    {
        algorithm_type_ = algorithm_type;
        emit algorithmTypeChanged();
        qDebug() << "********** changed algorithm_type to: " << algorithm_type_;
    }
}

/**
 * 在cpp中对property进行更改，ui中的参数也会实时更新
 * 注意：：不可以使用Q_PROPERTY中声明过的参数
 */
void FluxMapParameter::cppSetPixelNumX(int pixel_num_x)
{
    pixel_num_.setX(pixel_num_x);
    emit pixelNumXChanged();
}
void FluxMapParameter::cppSetPixelNumY(int pixel_num_y)
{
    pixel_num_.setY(pixel_num_y);
    emit pixelNumYChanged();
}
void FluxMapParameter::cppSetFluxMapPath(QString flux_map_path)
{
    flux_map_path_ = flux_map_path;
    emit fluxMapPathChanged();
}
void FluxMapParameter::cppSetTotalPower(float total_power)
{
    total_power_ = total_power;
    emit totalPowerChanged();
}
void FluxMapParameter::cppSetMaximumFlux(float maximum_flux)
{
    maximum_flux_ = maximum_flux;
    emit maximumFluxChanged();
}
void FluxMapParameter::cppSetMaximumFluxLocationX(int location_x)
{
    maximum_flux_location_.setX(location_x);
    emit maximumFluxLocationXChanged();
}
void FluxMapParameter::cppSetMaximumFluxLocationY(int location_y)
{
    maximum_flux_location_.setY(location_y);
    emit maximumFluxLocationYChanged();
}
